<?php

namespace app\admin\model\check;

use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Db;
use think\Loader;
use think\Model;

class FreeClean extends Model
{

    // 表名
    protected $name = 'free_clean';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    protected $updateTime = 'up_time';
    // 追加属性
    protected $append = [

    ];

    public function getOriginData()
    {
        return $this->origin;
    }


    public function getGenderList()
    {
        return ['1' => __('Male'), '0' => __('Female')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getPrevtimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['prevtime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['logintime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getJointimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['jointime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPrevtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLogintimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setJointimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setBirthdayAttr($value)
    {
        return $value ? $value : null;
    }

    public function getRejuctTypeList(){
        return [
            '请选择',
            '电梯使用标识不清晰',
            '联系电话联系不上',
            '电梯非加装电梯',
            '地址填写错误',
            '地址不在三环内',
        ];
    }
    public function saleman()
    {
        return $this->belongsTo('app\admin\model\User', 'salesman_id', 'uid', [], 'LEFT')->setEagerlyType(0);
    }
    public function trusteeshipType()
    {
        return $this->belongsTo('TrusteeshipType', 'tg_type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function myclass()
    {
        return $this->belongsTo('MyClass', 'my_class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


   public function  getDetailArr($row){
       if($row['check_time'] >0){
           $row['check_time'] = date('Y-m-d H:i:s',$row['check_time']);
       }
       if($row['submit_check_time'] >0){
           $row['submit_check_time'] = date('Y-m-d H:i:s',$row['submit_check_time']);
       }else{
           $row['submit_check_time'] = '-';
       }
       if($row['add_time'] >0){
           $row['add_time'] = date('Y-m-d H:i:s',$row['add_time']);
       }
       if($row['clean_area'] == 1){
           $row['clean_area_text'] = '轿厢内部四个面';
       }else if($row['clean_area'] == 2){
           $row['clean_area_text'] = '轿厢内部四个面+地板+厅门';
       }
       if($row['remark_type'] == 1){
           $row['remark_type_text'] = '电梯使用标识不清晰';
       }else if($row['remark_type'] == 2){
           $row['remark_type_text'] = '联系电话联系不上';
       }else if($row['remark_type'] == 3){
           $row['remark_type_text'] = '电梯非加装电梯';
       }else if($row['remark_type'] == 4){
           $row['remark_type_text'] = '地址填写错误';
       }else if($row['remark_type'] == 5){
           $row['remark_type_text'] = '地址不在三环内';
       }else{
           $row['remark_type_text'] = '';
       }
       if($row['is_can_update'] == 1){
           $row['is_can_update_text'] = '是';
       }else if($row['is_can_update'] == 0){
           $row['is_can_update_text'] = '否';
       }
       $row['accuracy'] = 0;
       if($row['lon']){
           $row['accuracy'] = 1;
       }
       $row['salesman'] = Db::name('user')->where(['uid'=>$row['salesman_id']])->value('real_name');
       return $row;
   }

}
